#ifndef SMOOTHSCROLL_H
#define SMOOTHSCROLL_H

#include <QList>
#include <QTimer>
#include <QQueue>
#include <QDateTime>
#include <QApplication>
#include <QScrollBar>
#include <QTreeWidget>
#include <QHeaderView>  // 隐藏树的head需要的头文件
#include <QTreeWidgetItem>

#define M_PI 3.14

class SmoothScroll : public QTreeWidget
{
    Q_OBJECT
public:
    explicit SmoothScroll(QWidget *parent = nullptr);

    enum SmoothMode
    {
        NO_SMOOTH,
        CONSTANT,
        LINEAR,
        QUADRATIC,
        COSINE
    };

    SmoothMode smoothMode();
    void       setSmoothMode(SmoothMode mode);

    int  fps();
    void setFps(int fps);

    // value in millisecond
    int  duration();
    void setDuration(int mesc);

    double acceration();
    void   setAcceration(double acceleration);

    double smallStepRatio();
    void   setSmallStepRatio(double smallStepRatio);

    double bigStepRatio();
    void   setBigStepRatio(double bigStepRatio);

    Qt::Modifier smallStepModifier();
    void         setSmallStepModifier(Qt::Modifier smallStepModifier);

    Qt::Modifier bigStepModifier();
    void         setbigStepModifier(Qt::Modifier bigStepModifier);

public slots:
    void slotSmoothMove();

protected:
    void wheelEvent(QWheelEvent *e);

private:
    double subDelta(double delta, int stepsLeft);

private:
    QTimer      *smoothMoveTimer;
    QWheelEvent *lastWheelEvent;

    int        m_fps;
    int        m_duration;
    SmoothMode m_smoothMode;

    double       m_acceleration;
    double       m_smallStepRatio;
    double       m_bigStepRatio;
    Qt::Modifier m_smallStepModifier;
    Qt::Modifier m_bigStepModifier;

    int stepsTotal;
    QList< QPair<double, int> > stepsLeftQueue;
};

#endif // SMOOTHSCROLL_H
